Option Explicit On Option Strict On Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents LstResults As System.Windows.Forms.ListBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents TxtWins As System.Windows.Forms.TextBox Friend WithEvents TxtLosses As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents BtnPlay As System.Windows.Forms.Button Friend WithEvents BtnReset As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.BtnPlay = New System.Windows.Forms.Button Me.LstResults = New System.Windows.Forms.ListBox Me.Label2 = New System.Windows.Forms.Label Me.TxtWins = New System.Windows.Forms.TextBox Me.TxtLosses = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.BtnReset = New System.Windows.Forms.Button Me.BtnQuit = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(184, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(102, 40) Me.Label1.TabIndex = 0 Me.Label1.Text = "Craps" ' 'BtnPlay ' Me.BtnPlay.Location = New System.Drawing.Point(48, 72) Me.BtnPlay.Name = "BtnPlay" Me.BtnPlay.Size = New System.Drawing.Size(88, 24) Me.BtnPlay.TabIndex = 1 Me.BtnPlay.Text = "Play" ' 'LstResults ' Me.LstResults.Location = New System.Drawing.Point(224, 72) Me.LstResults.Name = "LstResults" Me.LstResults.Size = New System.Drawing.Size(208, 173) Me.LstResults.TabIndex = 2 ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(8, 128) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(48, 16) Me.Label2.TabIndex = 3 Me.Label2.Text = "Wins" ' 'TxtWins ' Me.TxtWins.Location = New System.Drawing.Point(64, 128) Me.TxtWins.Name = "TxtWins" Me.TxtWins.ReadOnly = True Me.TxtWins.TabIndex = 4 Me.TxtWins.Text = "0" ' 'TxtLosses ' Me.TxtLosses.Location = New System.Drawing.Point(64, 168) Me.TxtLosses.Name = "TxtLosses" Me.TxtLosses.ReadOnly = True Me.TxtLosses.TabIndex = 6 Me.TxtLosses.Text = "0" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(8, 168) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(48, 16) Me.Label3.TabIndex = 5 Me.Label3.Text = "Losses" ' 'BtnReset ' Me.BtnReset.Location = New System.Drawing.Point(8, 216) Me.BtnReset.Name = "BtnReset" Me.BtnReset.Size = New System.Drawing.Size(72, 32) Me.BtnReset.TabIndex = 7 Me.BtnReset.Text = "Reset" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(96, 216) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(72, 32) Me.BtnQuit.TabIndex = 8 Me.BtnQuit.Text = "Quit" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(456, 341) Me.Controls.Add(Me.BtnQuit) Me.Controls.Add(Me.BtnReset) Me.Controls.Add(Me.TxtLosses) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.TxtWins) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.LstResults) Me.Controls.Add(Me.BtnPlay) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Function diceRoll() As Integer Dim rand As Integer ' generates random value between 0 and 5, then adds 1 rand = Convert.ToInt32(5 * Rnd() + 1) Return rand End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPlay.Click Dim dice1 As Integer Dim dice2 As Integer Dim winner As Boolean = False Dim loser As Boolean = False Dim point As Integer LstResults.Items.Clear() dice1 = diceRoll() dice2 = diceRoll() Dim total As Integer total = dice1 + dice2 LstResults.Items.Add("Roll: " & total & " (" & dice1 & " and " & dice2 & ")") Select Case total Case 7, 11 winner = True Case 2, 3, 12 loser = True Case Else point = total End Select Do Until winner Or loser ' roll until win or lose dice1 = diceRoll() dice2 = diceRoll() total = dice1 + dice2 LstResults.Items.Add("Roll: " & total & " (" & dice1 & " and " & dice2 & ")") If total = 7 Then loser = True ElseIf total = point Then winner = True End If Loop If winner Then MsgBox("You win!") Dim wins As Integer wins = Convert.ToInt32(TxtWins.Text) wins = wins + 1 TxtWins.Text = wins.ToString("") Else MsgBox("You lose, sucker!") Dim losses As Integer losses = Convert.ToInt32(TxtLosses.Text) losses = losses + 1 TxtLosses.Text = losses.ToString("") End If End Sub Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub BtnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReset.Click TxtWins.Text = "0" TxtLosses.Text = "0" LstResults.Items.Clear() End Sub End Class